<?php ob_start();?>
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
include($root.'/standart/head.php');
include($root.'/standart/dateHeader.php');
include($root.'/standart/checkUser.php');
$db = connect();
$menuId = $_GET["menu_id"];
$stmt ="SELECT ISFEATURED, ISPROMOTED FROM MENU_FEATURE WHERE MENU_ID = $menuId";
$res = $db->query($stmt) or die($stmt."<br/><br/>".mysql_error());
if($row = $res->fetch_assoc()){
	$featured = $row['ISFEATURED'];
	if(isset($_GET["featured"])){
		$featured = $_GET["featured"];
	}
	$promoted = $row['ISPROMOTED'];
	if(isset($_GET["promoted"])){
		$promoted = $_GET["promoted"];
	}
	$res->close();
	$stmt ="UPDATE MENU_FEATURE 
				SET ISFEATURED = ?, 
					ISPROMOTED = ? 
				WHERE MENU_ID = ?";
	$statement = $db->prepare($stmt);
	$statement->bind_param('ssi', $featured, $promoted, $menuId);
	if(!$statement->execute()){
		if(isset($_GET["featured"])){
			echo 'featured'.$menuId;
		}else{
			echo 'promoted'.$menuId;
		}
	}
	$statement->close();
}else{
	$featured = 'H';
	$promoted = 'H';
	if(isset($_GET["featured"])){
		$featured = $_GET["featured"];
	}
	if(isset($_GET["promoted"])){
		$promoted = $_GET["promoted"];
	}
	$stmt ="INSERT INTO MENU_FEATURE (MENU_ID, ISFEATURED, ISPROMOTED) VALUES(?,?,?)";
	$statement = $db->prepare($stmt);
	$statement->bind_param('iss', $menuId, $featured, $promoted);
	if(!$statement->execute()){
		if(isset($_GET["featured"])){
			echo 'featured'.$menuId;
		}else{
			echo 'promoted'.$menuId;
		}
	}
	$statement->close();
}
disconnect($db);
?>
<?php ob_end_flush(); ?>